<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="views/include :: header('系统配置')"/>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">参数名称</label>
                <div class="layui-input-block">
                    <input type="text" th:name="configName" lay-verify="required" lay-reqtext="参数名称不能为空"
                           placeholder="请输入参数名称" value="" class="layui-input">
                    <!--                    <tip>填写自己管理账号的名称。</tip>-->
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">参数键名</label>
                <div class="layui-input-block">
                    <input type="text" th:name="configKey" lay-verify="required" lay-reqtext="参数键名为空"
                           placeholder="请输入参数键名" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">参数键值</label>
                <div class="layui-input-block">
                    <input type="text" th:name="configValue" placeholder="请输入参数键值" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否系统内置</label>
                <div class="layui-input-block">
                    <input type="radio" name="configType" lay-filter="sm" value="Y" title="是" checked>
                    <input type="radio" name="configType" lay-filter="sm" value="N" title="否">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            $.ajax({
                url: "/config/saveOrUpdate",
                data: data.field,
                type: "post",
                //4.接收后台修改响应回来的数据；关闭弹出层、提示修改信息、刷新table
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            offset: '15px',
                            icon: 6,
                            time: 2000
                        }, function () {
                            parent.layer.close(index);
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 2000
                        });
                    }
                    //确认框关闭掉
                    layer.close(index);
                }
            });
            return false;//阻止跳转；
        });
    });
</script>
</body>
</html>